package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.service.IBrandService;
import com.ruoyi.product.vo.BrandCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.BrandCategory;
import com.ruoyi.product.service.IBrandCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 品牌分类关联Controller
 * 
 * @author 汤小洋
 * @date 2025-11-03
 */
@RestController
@RequestMapping("/brand/category")
public class BrandCategoryController extends BaseController
{
    @Autowired
    private IBrandCategoryService brandCategoryService;

    @Autowired
    private IBrandService brandService;

    /**
     * 查询品牌分类关联列表
     */
    @RequiresPermissions("product:brand/category:list")
    @GetMapping("/list")
    public TableDataInfo list(BrandCategory brandCategory)
    {
        startPage();
        List<BrandCategoryVo> list = brandCategoryService.selectBrandCategoryList(brandCategory);
        return getDataTable(list).put("brand", brandService.selectBrandByBrandId(brandCategory.getBrandId()));
    }

    /**
     * 获取品牌分类关联详细信息
     */
    @RequiresPermissions("product:brand/category:query")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return success(brandCategoryService.selectBrandCategoryByBrandId(brandId));
    }

    /**
     * 新增品牌分类关联
     */
    @RequiresPermissions("product:brand/category:add")
    @Log(title = "品牌分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrandCategory brandCategory)
    {
        return toAjax(brandCategoryService.insertBrandCategory(brandCategory));
    }

    /**
     * 修改品牌分类关联
     */
    @RequiresPermissions("product:brand/category:edit")
    @Log(title = "品牌分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrandCategory brandCategory)
    {
        return toAjax(brandCategoryService.updateBrandCategory(brandCategory));
    }

    /**
     * 删除品牌分类关联
     */
    @RequiresPermissions("product:brand/category:remove")
    @Log(title = "品牌分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping
    public AjaxResult remove(@RequestBody BrandCategoryVo brandCategoryVo)
    {
        return toAjax(brandCategoryService.deleteBrandCategory(brandCategoryVo));
    }
}
